package com.dylan.channel.v9.channel;

import java.nio.ByteBuffer;
import java.nio.channels.SelectableChannel;

public abstract class AbstractNioByteChannel extends AbstractNioChannel {


    protected AbstractNioByteChannel(Channel parent, SelectableChannel ch, int readInterestOp) {
        super(parent, ch, readInterestOp);
    }


    @Override
    protected AbstractNioUnsafe newUnsafe() {
        return new NioByteUnsafe();
    }
    protected abstract int doReadBytes(ByteBuffer buf) throws Exception;


    protected  class  NioByteUnsafe extends AbstractNioUnsafe{
        @Override
        public final void read() {
            //暂时用最原始简陋的方法处理
            ByteBuffer byteBuf = ByteBuffer.allocate(1024);
            try {
                doReadBytes(byteBuf);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

}
